import Vue from "vue";
import * as dayjs from "dayjs";

Vue.filter('NumberFormat', function (value) {
  if (!value) {
    return '0'
  }
  let intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') //将整数部分逢三一断
  return intPartFormat
})

Vue.filter('dayjs', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return dayjs(dataStr).format(pattern)
})

Vue.filter('moment', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return dayjs(dataStr).format(pattern)
})

/** 字符串超长截取省略号显示 */
Vue.filter('ellipsis', function (value, vlength = 25) {
  if(!value){
    return "";
  }
  console.log('vlength: '+ vlength);
  if (value.length > vlength) {
    return value.slice(0, vlength) + '...'
  }
  return value
})


export const companyStatusFilter = key => {
  switch (key) {
    case 1:
      return '创建中';
    case 2:
      return '审批中';
    case 3:
      return '已入库';
    case 10:
      return '审批不通过';
    default:
      return '';
  }
};
export const companyChangeStatusFilter = key => {
  switch (key) {
    case 1:
      return '变更中';
    case 2:
      return '审批中';
    case 3:
      return '已入库';
    case 10:
      return '审批不通过';
    default:
      return '';
  }
};

export const projectStatusFilter = key => {
  switch (key) {
    case 1:
      return '创建中';
    case 2:
      return '审批中';
    case 3:
      return '上会中';
    case 4:
      return '执行中';
    case 5:
      return '验收中';
    case 6:
      return '结题';
    case 7:
      return '立项不通过';
    case 10:
      return '转储';
    default:
      return '';
  }
};

export const projectRewardStatusFilter = status => {
  let name = ''
  switch (status) {
    case 1:
      name = '创建中'
      break;
    case 2:
      name = '审批中'
      break;
    case 3:
      name = '审批完成'
      break;
    case 4:
      name = '审批不通过'
      break;
    default:
      break;
  }
  return name;
};


export const stdSampleStatusFilter = status => {
  let name = ''
  switch (status) {
    case 1:
      name = '草稿'
      break;
    case 2:
      name = '审批中'
      break;
    case 3:
      name = '待执行'
      break;
    case 4:
      name = '生效中'
      break;
    case 9:
      name = '审批不通过'
      break;
    case 10:
      name = '已作废'
      break;
    default:
      break;
  }
  return name;
};

export const stdSampleStatusTbFilters = [
  {
    text: '草稿',
    value: '1'
  },
  {
    text: '审批中',
    value: '2'
  },
  {
    text: '待执行',
    value: '3'
  },
   {
    text: '生效中',
    value: '4'
  },
   {
    text: '审批不通过',
    value: '9'
  },
   {
    text: '已作废',
    value: '10'
  }
]